package com.ptma.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * 
 * @author YahyaArshad
 * 
 */
@Entity
@Table(name = "USER_GROUP")
public class Group implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(name = "group_id")
	private Long id;

	@Column(name = "group_name")
	private String name;

	@Column(name = "comment")
	private String comment;

	@Column(name = "create_time")
	private Timestamp createTime = new Timestamp(System.currentTimeMillis());

	@ManyToMany
	@Cascade(value = CascadeType.SAVE_UPDATE)
	@JoinTable(name = "GROUP_DEVICES", joinColumns = { @JoinColumn(name = "fk_group_id", nullable = false, updatable = false, referencedColumnName = "group_id") }, inverseJoinColumns = { @JoinColumn(name = "fk_device_id", referencedColumnName = "device_id", nullable = false, updatable = false) })
	private Set<Device> devices;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	public Group(String name) {

		this.name = name;
	}

	public Group() {

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Device> getDevices() {
		return devices;
	}

	public void setDevices(Set<Device> devices) {
		this.devices = devices;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

}
